package com.example.manu_facturer_orders.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.manu_facturer_orders.pojo.ManuFacturerVO;
import com.example.manu_facturer_orders.pojo.PageResult;
import com.example.manu_facturer_orders.service.ManuFacturerService;
import commons.Result;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: tobed
 * @date: 2022/9/8
 * @time: 8:24
 */
@RestController
@RequestMapping("manuFacturerController")
public class ManuFacturerController {

    @Autowired
    ManuFacturerService manuFacturerService;

    /**
     * 厂商全查
     * @param manufacturerType
     * @param manufacturerCode
     * @param manufacturerUseType
     * @param pageResult
     * @return
     */
    @RequestMapping("list")
    public Result list(
            @RequestParam String manufacturerType,
            @RequestParam String manufacturerCode,
            @RequestParam String manufacturerUseType,
            PageResult pageResult){
        Page<ManuFacturerVO> manuFacturerPage = manuFacturerService.listManuFacturer(manufacturerCode,manufacturerType,manufacturerUseType,new Page<>(pageResult.getPageNum(), pageResult.getPageSize()));
        return Result.success(manuFacturerPage);
    }

    /**
     * 自行注册厂商全查无分页
     * @param manufacturerType
     * @param manufacturerCode
     * @param manufacturerUseType
     * @param pageResult
     * @return
     */
    @RequestMapping("listNo")
    public Result listNo(
            @RequestParam String manufacturerType,
            @RequestParam String manufacturerCode,
            @RequestParam String manufacturerUseType,
            PageResult pageResult){
        Page<ManuFacturerVO> manuFacturerPage = manuFacturerService.listNoManuFacturer(manufacturerCode,manufacturerType,manufacturerUseType,new Page<>(pageResult.getPageNum(), pageResult.getPageSize()));
        return Result.success(manuFacturerPage);
    }

    /**
     * 签约厂商
     * @param id
     * @param contractStartDate
     * @param contractEndDate
     * @return
     */
    @RequestMapping("contractManuFacturer")
    public Result contractManuFacturer(
            @RequestParam Integer id,
            @RequestParam String contractStartDate,
            @RequestParam String contractEndDate){
        Result result = manuFacturerService.contractManuFacturer(contractStartDate,contractEndDate,id);
        return result;
    }

    /**
     * 自行注册厂商处理
     * @param id
     * @param manufacturerDelMessage
     * @return
     */
    @RequestMapping("dealManuFacturer")
    public Result dealManuFacturer(
            @RequestParam Integer id,
            @RequestParam String manufacturerDelMessage,
            @RequestParam Integer manufacturerDelType){
        Result result = manuFacturerService.dealManuFacturer(id,manufacturerDelMessage,manufacturerDelType);
        return result;
    }

    /**
     * 解约厂商
     * @param id
     * @return
     */
    @DeleteMapping("jieyueFactur")
    public Result jieyueFactur(@RequestParam Integer id){
        Result result = manuFacturerService.jieyueFactur(id);
        return  result;
    }

    /**
     * 厂商全查无分页
     * @return
     */
    @RequestMapping("listNoPage")
    public Result listNoPage(){
        List<ManuFacturerVO> list = manuFacturerService.listNo();
        return Result.success(list);
    }

    /**
     * 真全查
     * @return
     */
    @RequestMapping("allList")
    public Result allList(){
        List<ManuFacturerVO> allList = manuFacturerService.allList();
        return Result.success(allList);
    }

    /**
     * 真全查
     * @return
     */
    @RequestMapping("allList1")
    public Result allList1(){
        List<ManuFacturerVO> list = manuFacturerService.allList();
        return Result.success(list);
    }

    /**
     * 单查名称
     * @param id
     * @return
     */
    @RequestMapping("getNameByPkid")
    public String getNameByPkid(@Param("id") Integer id){
        String name = manuFacturerService.getNameByPkid(id);
        return name;
    }

    /**
     * 停用/启用
     * @param id
     * @param manufacturerUseType
     * @return
     */
    @DeleteMapping("closeManuFacturer")
    public Result closeManuFacturer(@RequestParam Integer id,@RequestParam Integer manufacturerUseType){
        Result result = manuFacturerService.closeManuFacturer(id,manufacturerUseType);
        return result;
    }


}
